#include <iostream>
#include <vector>
#include <algorithm>
#include <random>
#include <tbb/tbb.h>

// 生成一万数据的函数
std::vector<int> generate_data(size_t size) {
    std::vector<int> data(size);
    std::random_device rd;
    std::mt19937 mt(rd());
    std::uniform_int_distribution<int> dist(1, 10000);

    for (size_t i = 0; i < size; ++i) {
        data[i] = dist(mt);
    }
    return data;
}

// 并行排序函数
void parallel_sort(std::vector<int>& data) {
    tbb::parallel_sort(data.begin(), data.end());
}

int main() {
    size_t data_size = 10000;
    std::vector<int> data = generate_data(data_size);

    std::cout << "Before sorting: ";
    for (size_t i = 0; i < 10; ++i) {  // 打印前10个数据
        std::cout << data[i] << " ";
    }
    std::cout << "..." << std::endl;

    // 使用 TBB 进行并行排序
    parallel_sort(data);

    std::cout << "After sorting: ";
    for (size_t i = 0; i < 10; ++i) {  // 打印前10个数据
        std::cout << data[i] << " ";
    }
    std::cout << "..." << std::endl;


    return 0;
}
